export const uiCollection = {

	//首页显示时间获取
	getDate(type ?) {
		var date = new Date();
		var year = date.getFullYear(),
			month = ("0" + (date.getMonth() + 1)).slice(-2),
			sdate = ("0" + date.getDate()).slice(-2),
			hour = ("0" + date.getHours()).slice(-2),
			minute = ("0" + date.getMinutes()).slice(-2),
			second = ("0" + date.getSeconds()).slice(-2);

		let resStr = "";
		resStr =
			year +
			"年" +
			month +
			"月" +
			sdate +
			"日" +
			hour +
			":" +
			minute +
			":" +
			second;

		if (type == "hour") {
			resStr = hour + ":" + minute
		}

		return resStr;
	},
	//在线挂号页面展示日期/星期 入参为要获取的天数
	getDay(day : Number) {
		let today = new Date();

		let targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;

		today.setTime(targetday_milliseconds); //注意，这行是关键代码

		let tYear = today.getFullYear();
		let tMonth = today.getMonth();
		let tDate = today.getDate();
		tMonth = this.doHandleMonth(tMonth + 1);
		tDate = this.doHandleMonth(tDate);

		let datelist = ['周日', '周一', '周二', '周三', '周四', '周五', '周六',]
		return tYear + "-" + tMonth + "-" + tDate + "|" + datelist[new Date(tYear + "-" + tMonth + "-" + tDate).getDay()];

	},
	doHandleMonth(month : Number) {
		let m = month;
		if (month.toString().length == 1) {
			m = "0" + month;
		}
		return m;
	},

	showModal(content : string) {
		return new Promise((resolve) => {
			uni.showModal({
				title: '提示',
				content: content,
				showCancel: true,
				mask: true,
				success(res) {
					if (res.confirm) {
						resolve(true);
					} else {
						resolve(false);
					}

				}
			})
		})
	},

	showLoading(msg : string) {
		uni.showLoading({
			title: msg,
			mask: true,
		});

		setTimeout(() => {
			uni.hideLoading()
		}, 30000)
	},

	hideLoading() {
		uni.hideLoading()
	},

	showToast(msg : string) {
		uni.showToast({
			title: msg,
			mask: true,
			duration: 2000,
			icon: 'none'
		})
	},

	TimeDate(now, type?) {
		var year = now.getFullYear();
		var month = now.getMonth() + 1;
		var date = now.getDate();
		var hour = now.getHours();
		var minute = now.getMinutes();
		var second = now.getSeconds();
		if (type == "noSecond") {
			return year + "-" + month + "-" + date + " " + hour + ":" + minute
		}
		return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
	},
	
	
	enterIdCard(){
		return new Promise((resolve)=>{
			uni.showModal({
				title: '请输入身份证号进行验证',
				editable:true,
			    success:  (res)=> {
			        console.log("请输入身份证信息返回内容",res);
					if (res.confirm) {
						
						let check = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
						check.test(res.content)?resolve({idCard:res.content,status:true}):resolve({status:true,idCard:''});
					} else {
						resolve({status:false});
					}
					
			    }
			});
		})
	}
};